package com.sinopac.actionCore;

import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@ParentPackage("defaults")
public class ActionCore extends ActionSupport{

	protected static final long serialVersionUID = 1L;
	protected static final String LOGOUT = "logout";
	protected static final String SUCCEED = "succeed";
	protected ActionContext actionContext = ActionContext.getContext();
    protected Map<String,Object> session = actionContext.getSession();
    protected static final String CustomersID = "customer_id";
    protected static final String TOKEN_ESN = "token_esn";
    protected static final String USER_NAME = "userName";
    protected static final String USER_ROLES = "userRoles";
    //For Json
    private String jsonResult;
	
	@Action(value="backMain",results={@Result(name="success",type="redirect",location="/Index/index")})
	public String backMain(){
		String strtmp = (String)session.get(USER_NAME);
		String newMd5 = (String)session.get("newMd5");
		String pdfPath = (String)session.get("pdfPath");
		String userRoles = (String)session.get(USER_ROLES);
		System.out.println("pdfPath:" + pdfPath);
		session.clear();
		session.put(USER_NAME, strtmp);
		session.put("newMd5", newMd5);
		session.put("pdfPath", pdfPath);
		session.put(USER_ROLES, userRoles);
		return SUCCESS;
	}
	
	@Action(value="logOutMain",results={@Result(name="success",type="redirect",location="/Index/login")})
	public String logOutMain(){
//		String strtmp = (String)session.get(USER_NAME);
//		String newMd5 = (String)session.get("newMd5");
		session.clear();
//		session.put(USER_NAME, strtmp);
//		session.put("otpMd5", otpMd5);
		return SUCCESS;
	}

	public String getJsonResult() {
		return jsonResult;
	}

	public void setJsonResult(String jsonResult) {
		this.jsonResult = jsonResult;
	}
}
